package com.epro.dx.task;

import java.util.ArrayList;

import com.epro.dx.listenner.MyAsyncTaskListenner;
import com.epro.dx.util.ActivityUtil;
import com.weipu.common.facade.exception.DxException;
import com.weipu.common.facade.factory.ProviderFactory;
import com.weipu.common.facade.model.MessageModel;

import android.content.Context;
import android.os.AsyncTask;

/************************
 * @author Tony
 * @Date:2016-5-3上午11:25:19
 * @描述:获取消息列表
 ************************/
public class GetNoticesAsyncTask extends BaseNeedReLoginTask {

	private MyAsyncTaskListenner myAsyncTaskListenner;
	private int noticeType;
	private int pageIndex;
	private int pageSize;
	private ArrayList<MessageModel> notices;
	private Context mContext;
	public GetNoticesAsyncTask(Context mContext,int noticeType,int pageIndex,int pageSize,MyAsyncTaskListenner myAsyncTaskListenner){
		this.mContext = mContext;
		this.noticeType = noticeType;
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
		this.myAsyncTaskListenner = myAsyncTaskListenner;
		
	}
	@Override
	protected void onPreExecute() {
		if(null!=myAsyncTaskListenner){
			myAsyncTaskListenner.onPreTask();
		}
		super.onPreExecute();
	}
	@Override
	protected String doInBackground(Void... params) {
		try {
			notices = ProviderFactory.createMessageService().getNotices(ActivityUtil.getCustomerID(), ActivityUtil.getCustomerToken(),noticeType,pageIndex,pageSize);
		} catch (DxException e) {
			return e.getErrCode();
		}
		return "0";
	}
	@Override
	protected void onPostExecute(String result) {
		super.onPostExecute(result);
		if(null!=myAsyncTaskListenner && !isRelogin){
			myAsyncTaskListenner.onPostTask(result, notices);
		}
	}
	@Override
	protected Context setContext() {
		return mContext;
	}
	@Override
	protected BaseNeedReLoginTask setTask() {
		return new GetNoticesAsyncTask(mContext, noticeType, pageIndex, pageSize, myAsyncTaskListenner);
	}

}
